@extends('admin.app')
@section('content')
    <link rel="stylesheet" href="/css/admin/set-up.css">

    <div class="mian-container">
        <div class="main-con set-up">
            <div class="setup-top weui-cell">
                <div class="btn-weui weui-cell__hd">
                    <img class="full-topimg" src={{"/uploads/images/company-logo/".$company->corpid.".png"}}>
                    <p class="btn-p">上传图片</p>
                </div>
                <div class="setup-bd weui-cell__bd">
                    <img class="question-btn" src="/images/admin/full-infor1.png">
                    <p class="change-ctitle">{{$company->name}}</p>
                    <i class="change-icon icon iconfont icon-xiugai "></i>
                </div>
            </div>
            <div class="weui-cells slogan-cells">
                <div class="weui-cell">
                    <div class="weui-cell__bd">
                        <p style="max-width: 95%;font-size: 16px;" class="change-slogan">{{$company->slogan}}</p>
                    </div>
                    <div class="weui-cell__ft"><i class="icon-slogan icon iconfont icon-xiugai"></i>   </div>
                </div>
            </div>
          {{--  <div class="copy-text">
                <p id="text">企业链接：www.123456.com</p><p id="copy">复制</p>
            </div>
            <div class="weui-cells">
                <a class="change-skin weui-cell weui-cell_access" href="javascript:;">
                    <div class="weui-cell__hd"><img src="/images/admin/setup-skin1.png"></div>
                    <div class="weui-cell__bd">
                        <p>个性换肤</p>
                    </div>
                    <div class="weui-cell__ft">
                    </div>
                </a>
            </div>--}}

            <div class="weui-cells">
                <a class="change-skin weui-cell weui-cell_access" href="/sysadmin/feedback/feedback">
                    <div class="weui-cell__hd"><img src="/images/admin/set-1.png"></div>
                    <div class="weui-cell__bd">
                        <p>月度意见<small>-设置</small></p>
                    </div>
                    <div class="weui-cell__ft">
                    </div>
                </a>
            </div>
{{--            <div class="weui-cells">
                <a class="change-skin weui-cell weui-cell_access" href="javascript:;">
                    <div class="weui-cell__hd"><img src="/images/admin/set-2.png"></div>
                    <div class="weui-cell__bd">
                        <p>奖惩<small>-初始化</small></p>
                    </div>
                    <div class="weui-cell__ft">
                    </div>
                </a>
            </div>--}}
            <div class="weui-cells">
                <a class="change-skin weui-cell weui-cell_access" href="/admin/set/attendance_edit">
                    <div class="weui-cell__hd"><img src="/images/admin/set-3.png"></div>
                    <div class="weui-cell__bd">
                        <p>考勤<small>-设置</small></p>
                    </div>
                    <div class="weui-cell__ft">
                    </div>
                </a>
            </div>
            <div class="weui-cells">
                <a class="change-skin weui-cell weui-cell_access" href="/sysadmin/reward/reward-punish-set">
                    <div class="weui-cell__hd"><img src="/images/admin/set-1.png"></div>
                    <div class="weui-cell__bd">
                        <p>奖惩<small>-设置</small></p>
                    </div>
                    <div class="weui-cell__ft">
                    </div>
                </a>
            </div>
        </div>

        @include('sysadmin.admin-caidan')

        <!--图片裁剪-->
        <div class="clipbg displaynone">
            <div id="clipArea"></div>
            <div class="loading displaynone">正在载入图片...</div>
            <div class="footer">
                <dl>
                    <dd style="background: #fe1041; color: #ffffff;border: none;">打开相册<input type="file" id="file" accept="image/*" ></dd>
                    <dd id="clipBtn">完成裁剪</dd>
                </dl>
                <div class="back">取消</div>
            </div>
        </div>
    </div>

    <script src="/addons/phtotclip/hammer.min.js"></script>
    <script src="/addons/phtotclip/iscroll-zoom-min.js"></script>
    <script src="/addons/phtotclip/lrz.all.bundle.js?v=1"></script>
    <script src="/addons/phtotclip/photoClip.js?v=1"></script>
    <script>

        $('.admin-item').click(function(){
            $('.front-show-hidden').toggle();
        });
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
        $(document).ready(function () {
            $("#copy").on("click",function(){
                var  val = $("#text").text();
                Clipboard.copy(val);
            });

            //上传头像start
            $(".btn-p").click(function(){
                $(".clipbg").fadeIn()
            })
            var clipArea = new  PhotoClip("#clipArea", {
                size: [300, 300],//裁剪框大小
                outputSize:[0,0],//打开图片大小，[0,0]表示原图大小
                file: "#file",
                ok: "#clipBtn",
                loadStart: function() { //图片开始加载的回调函数。this 指向当前 PhotoClip 的实例对象，并将正在加载的 file 对象作为参数传入。（如果是使用非 file 的方式加载图片，则该参数为图片的 url）
                    $(".loading").removeClass("displaynone");

                },
                loadComplete: function() {//图片加载完成的回调函数。this 指向当前 PhotoClip 的实例对象，并将图片的 <img> 对象作为参数传入。
                    $(".loading").addClass("displaynone");

                },
                done: function(dataURL) { //裁剪完成的回调函数。this 指向当前 PhotoClip 的实例对象，会将裁剪出的图像数据DataURL作为参数传入。
                    $.ajax({
                        'url': '/admin/Upload/companyLogo',
                        'type': 'POST',
                        'data': {'dataURL': dataURL},
                        error: function (request) {
                            $.toptip("网络异常请重试",'warning');
                            setTimeout(function(){window.location.reload();},2000);

                        },
                        success: function (data) {
                            if (data.status == 'success') {
                                $.toptip("头像修改成功",'success');

                            } else {
                                $.toptip("网络异常请重试",'warning');
                                setTimeout(function(){window.location.reload();},2000);
                            }
                        },
                    });
                    $('.full-topimg').attr("src",dataURL);
                    $(".clipbg").fadeOut();
                }
            });
            $(".back").click(function(){
                $(".clipbg").fadeOut();
            })
            //上传头像end
            $('.question-btn').click(function(){
                $.toast("上传的头像建议png格式", "text");
            })
            $('.change-icon').click(function(){
                var input=$('<textarea type="text" class="weui-textarea edit-com" id="e_name">'+$('.change-ctitle').text()+'</textarea>');
                $('.change-ctitle').html(input);
                $('#e_name').attr("readonly",false).focus();
                var result = $('#e_name').val();
                $('#e_name').val('');
                $('#e_name').val(result);
                $('#e_name').click(function(){
                    return false;
                });
                $('#e_name').blur(function(){
                    $(".change-ctitle").html($(this).val());
                    ajax_set_update();
                })
            })
            $('.icon-slogan').click(function(){
                var input=$('<textarea type="text" class="weui-textarea edit-com" id="e_slogan">'+$('.change-slogan').text()+'</textarea>');
                $('.change-slogan').html(input);
                $('#e_slogan').attr("readonly",false).focus();
                var result = $('#e_slogan').val();
                console.log(result)
                $('#e_slogan').val('');
                $('#e_slogan').val(result);
                $('#e_slogan').click(function(){
                    return false;
                });
                //11111
                $('#e_slogan').blur(function(){
                    $(".change-slogan").html($(this).val());
                    ajax_set_update()
                })
            });
            $('.kaohe-item').click(function(){
                $('.show-hidden').toggle();
            })

            function ajax_set_update() {
                var url='/admin/set/company_update';
                var name = $('.change-ctitle textarea').val() || $('.change-ctitle').html();
                var slogan =$('.change-slogan textarea').val() || $('.change-slogan').html()||'';
                if (name.length==0||name.length >30) {
                    $.toptip('请保持公司名称在30字内！');
                    return false;/*阻止表单提交*/
                } else if (slogan.length>50) {
                    $.toptip('请保持宣传语在50字内！');
                    return false;/*阻止表单提交*/
                }
                $.ajax({
                    type: 'put',
                    cache: 'false',
                    url: url,
                    data: 'name=' + name + '&slogan=' + slogan,
                    dataType: 'json',
                    success: function (data) {
                        if (data.status == 'success') {
                            $.toptip(data.msg,'success');
                        } else {
                            $.toptip(data.msg,'error');
                            window.location.href= data.redirectUrl;
                        }
                    },
                    error: function () {
                        $.toptip('网络异常请重试','warning');
                    }
                });
            }
        })
    </script>
@endsection
